﻿@{
    ViewBag.Title = "用户客户关系管理";
    Layout = "~/Views/Shared/Main.cshtml";
}
<div class="row">
    <div class="span10"></div>
    <div class="span2">
        <a href="#" class="btn" id="btnAddModal">Add</a>
    </div>
</div>
<table class="table table-hover">
    <thead>
        <tr>
            <th>用户</th>
            <th>客户</th>
            <th></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in (List<ASoft.Web.Base.CustomAUser>)ViewData["grid"])
        {
            <tr>
                <td>@item.AUserFK</td>
                <td>@item.CustomFK</td>
                <td><a href="#" onclick="del('@item.CustomAUserId')"><i class="icon-trash"></i></a></td>
            </tr>
        }
    </tbody>
</table>
<div class="row">
    @Html.Partial("TablePager")
</div>
<div id="addModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">用户客户关系维护</h3>
    </div>
    <div class="modal-body" id="detailDiv">
        <div class="form-horizontal">
            <div class="control-group">
                <label class="control-label" for="Code">用户</label>
                <div class="controls">
                    <select id="AUserId" name="AUserId">
                        @foreach (var item in (List<ASoft.Web.Base.AUser>)ViewData["users"])
                        {
                            <option value="@item.AUserId">@item.ToString()</option>
                        }
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="CName">客户</label>
                <div class="controls">
                    <select id="CustomId" name="CustomId">
                        @foreach (var item in (List<ASoft.Web.Base.Custom>)ViewData["customs"])
                        {
                            <option value="@item.CustomId">@item.ToString()</option>
                        }
                    </select>

                </div>
            </div>
            <input type="hidden" id="CustomAUserId" name="CustomAUserId" />
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
        <button class="btn btn-primary" id="btnSave">保存</button>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#btnSave").click(function () {
            var id = $("#CustomAUserId").val();
            var actionName = "update";
            if (id == "0") {
                actionName = "add";
            }
            $.myjs.ajax(actionName, "detailDiv", function () { window.location.reload(); });
        });

        $("#btnAddModal").click(function () {
            setMoalValue(0, '', '', '');
            $('#myModalLabel').text("添加客户");
            $('#addModal').modal('show')
        });
    });

    function del(id) {
        setMoalValue(id, "", "", "");
        $.myjs.ajax("delete", "detailDiv", function () { window.location.reload(); });
    }

    function setMoalValue(id, auserid, customid) {
        $("#CustomAUserId").val(id);
        $("#AUserId").val(auserid);
        $("#CustomId").val(customid);
    }
</script>
